package com.cloud.mall.test.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.cloud.mall.dto.test.Product;
import com.cloud.mall.test.entity.ProductTbl;
import com.cloud.mall.test.mapper.ProductTblMapper;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: 梁二东
 * @Date: 2024/12/16 11:37
 * @Description:
 **/
@Service
@Slf4j
public class ProductTblServiceImpl implements ProductTblService {

    @Autowired
    private ProductTblMapper productTblMapper;

    @Override
    public Product selectByCommodityCode(String commodityCode) {
        String xid = RootContext.getXID();
        log.info("开始查询商品信息，全局事务xid：【{}】", xid);
        ProductTbl productTbl = productTblMapper.selectByCommodityCode(commodityCode);
        log.info("查询商品信息结果：【{}】，全局事务xid：【{}】", JSONUtil.toJsonStr(productTbl), xid);
        return BeanUtil.toBean(productTbl, Product.class);
    }
}
